package A1_2_College;

import java.util.ArrayList;
import java.util.List;

// 建筑类
class Building {
    private String name;
    private String address;

    public Building(String name, String address) {
        this.name = name;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public String getAddress() {
        return address;
    }
}

// 课程类
class Course {
    private String name;
    private int credit;
    private Building building; // 课程所在建筑，体现约束

    public Course(String name, int credit, Building building) {
        this.name = name;
        this.credit = credit;
        this.building = building;
    }

    public String getName() {
        return name;
    }

    public int getCredit() {
        return credit;
    }

    public Building getBuilding() {
        return building;
    }
}

// 学院类
class College {
    private String name;
    private List<Building> buildings; // 聚合关系：学院包含多个建筑
    private List<Course> courses; // 组合关系：学院包含多个课程

    public College(String name) {
        this.name = name;
        this.buildings = new ArrayList<>();
        this.courses = new ArrayList<>();
    }

    // 添加建筑（聚合关系，建筑可独立存在）
    public void addBuilding(Building building) {
        buildings.add(building);
    }

    // 添加课程（组合关系，课程依赖学院存在）
    public void addCourse(Course course) {
        courses.add(course);
    }

    // 获取学院信息
    public void getCollegeInfo() {
        System.out.println("学院名称：" + name);
        System.out.println("学院建筑：");
        for (Building building : buildings) {
            System.out.println("- " + building.getName() + "（地址：" + building.getAddress() + "）");
        }
        System.out.println("学院课程：");
        for (Course course : courses) {
            System.out.println("- " + course.getName() + "（学分：" + course.getCredit() + "，上课地点：" + course.getBuilding().getName() + "）");
        }
    }
}